layui.use(['form', 'layedit', 'laydate','table'], function(){
  var table = layui.table
  ,laydate = layui.laydate
  ,form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,upload = layui.upload;
  
  $('#sub').on('click', function(){
	  	 var oldPwd = $("#oldPwd").val();	//旧密码
	  	var newPwd = $("#newPwd").val();	//新密码
	  	var newPwds = $("#newPwds").val();	//确认密码
	  	 var url="../../../role/findOldPwd.action"; 
		 var data={"oldPwd":oldPwd};
		 $.post(url,data,function(mes){
			 if(mes == 0){
				 parent.layer.msg('旧密码不正确!', {
				      icon: 5,
				      anim :6
				  });
			 }else {
				 if(newPwd == newPwds){
					 var url="../../../role/updatePwd.action"; 
					 var data={"newPwd":newPwd};
					 $.post(url,data,function(mes){
						if(mes > 0){
							parent.layer.msg('修改成功,请重新登录!', {
							      icon: 6,
							      anim :6,
							      time:2000
							  });
							exit();
						}else{
							parent.layer.msg('修改密码失败!', {
							      icon: 5,
							      anim :6
							  });
						}
					 },"json");
				 }else{
					 parent.layer.msg('两次密码不一致!', {
					      icon: 5,
					      anim :6
					  });
				 }
			 }
		 },"json");
  });
  load();
});

/**
 * 退出Session
 * @returns
 */
function exit(){
	var url="../../../role/exitUser.action";
	var data=null;
	$.post(url,data,function(mes){
		if(mes == 1){
			parent.location.href="../../login/login.html";
		}
	},"json");
}